﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace STAR.Spring.Framework.Module
{
    public partial class SpringService
    {
        ExecuteService service = new ExecuteService();

        /// <summary>
        /// 单请求
        /// </summary>
        /// <param name="op"></param>
        /// <param name="isCustom"></param>
        /// <param name="requestParms"></param>
        /// <returns></returns>
        internal string GetResultString(string op, bool isCustom, RequestJsonParmInfo requestParms)
        {
            ReturnInfo info = GetResultInfo(op, isCustom, requestParms);
            return info.ToBaseResponse();
        }
        
        /// <summary>
        /// 多请求
        /// </summary>
        /// <param name="requestInfo"></param>
        /// <returns></returns>
        internal  string GetMultipleRequest(RequestJsonParmInfos requestInfo)
        {
            List<ReturnInfo> infos = new List<ReturnInfo>();
            for (int index = 0; index < requestInfo.Items.Length; index++)
            {
                infos.Add(GetResultInfo(requestInfo.Items[index].Op, requestInfo.Items[index].IsCustom,
                    new RequestJsonParmInfo()
                    {
                        Parms = requestInfo.Items[index].Parms,
                        RequestName = requestInfo.Items[index].RequestName
                    })
                );
            }
            return infos.ToBaseResponse();
        }

        #region 总体操作
        internal ReturnInfo GetResultInfo(string op, bool isCustom, RequestJsonParmInfo requestParms)
        {
            ReturnInfo result = null;
            switch (op)
            {
                case "GetValueRequest":
                    HttpContext.Current.Response.ContentType = "text/json";
                    result = GetValueRequest(isCustom, requestParms);
                    break;
                case "GetObjectRequest":
                    result = GetObjectRequest(isCustom, requestParms);
                    break;
                case "GetListRequest":
                    result = GetListRequest(isCustom, requestParms);
                    break;
                case "CustomRequest":
                    result = GetFullCustomRequest(isCustom, requestParms);
                    break;
                //case "FullCustomRequest":
                //    result = service.GetFullCustomRequest(requestParms.RequestName, requestParms.Parms);
                //    break;
                default:
                    break;
            }
            return result;
        }
        #region 各类型请求
        
        public ReturnInfo GetValueRequest(bool isCustom, RequestJsonParmInfo info)
        {
            return service.GetValueRequest(isCustom, info);
        }
        public ReturnInfo GetObjectRequest(bool isCustom, RequestJsonParmInfo info)
        {
            return service.GetObjectRequest(isCustom, info);
        }
        public ReturnInfo GetListRequest(bool isCustom, RequestJsonParmInfo info)
        {
            return service.GetListRequest(isCustom, info);
        }
        //public string GetCustomRequest(bool isCustom, RequestJsonParmInfo info)
        //{
        //    return service.GetCustomRequest(isCustom, info).ToBaseResponse();
        //}
        public ReturnInfo GetFullCustomRequest(bool isCustom, RequestJsonParmInfo info)
        {
            return service.GetFullCustomRequest(info);
        }
        #endregion 
        #endregion
    }
}
